
#import "MyObject.h"

@implementation MyObject
	

- appDidInit:sender
{

	char annee[5], mois[5], jour[5], buff[30];
	long time(), tmpTime;
	struct tm *tm, *localtime();
	int year, month, day;
	

	fichier = "Library/MemoPad/note.memopad.rtfd";

	error = [mainWindow setFrameUsingName:"WindowFrameMemoPad"];
	[self loadPad:self];
	[mainWindow orderFront:self];

    		
	tmpTime = time(0);
	tm = localtime( &tmpTime );
	day = (tm->tm_mday);
	month = (tm->tm_mon) + 1;
	year = (tm->tm_year);

	if (month <10)
	  sprintf(mois, "0%d", month);
	else
	  sprintf(mois, "%d", month);

	if (day <10)
	  sprintf(jour, "0%d", day);
	else
	  sprintf(jour, "%d", day);

	sprintf(annee, "%d", year);

	strcat(buff, annee);
	strcat(buff, mois);
	strcat(buff, jour);

	[date setStringValue:buff];

	if ([pad findText:buff 
               ignoreCase:YES 
                backwards:NO 
                     wrap:YES] == YES)
	
	NXBeep();


	return self;
}

- appWillTerminate:sender
{
	[self savePad:self];
	[mainWindow saveFrameUsingName:"WindowFrameMemoPad"];

	return self;

}


- openWindow:sender
{
	[mainWindow makeKeyAndOrderFront:self];

	return self;
}


- notebook:sender
{
	[self savePad:self];

	fichier = "Library/MemoPad/note.memopad.rtfd";

	[self loadPad:self];

    	return self;
}

- scrapbook:sender
{
	[self savePad:self];

	fichier = "Library/MemoPad/scrap.memopad.rtfd";

	[self loadPad:self];

    	return self;
}


- reference:sender
{
	[self savePad:self];

	fichier = "Library/MemoPad/reference.memopad.rtfd";

	[self loadPad:self];

    	return self;
}

- telephonebook:sender
{
	[self savePad:self];

	fichier = "Library/MemoPad/telephone.memopad.rtfd";

	[self loadPad:self];

    	return self;
}


- loadPad:sender
{

	error = [pad openRTFDFrom:fichier];
	
    	return self;

}


- savePad:sender
{
	
	error = [pad saveRTFDTo:fichier
		   removeBackup:YES
		   errorHandler:self];
		   
	return self;
}

- attemptOverwrite:fichier
{
	NXBeep();

	return self;
}



- ShowInfoPanel:sender
{
  	NXBeep();

	if (!infoPanel)
		[NXApp loadNibSection:"infoPanel.nib" owner:self];
		
	[infoPanel makeKeyAndOrderFront:self];
	
    return self;
}

- showMoreInfoPanel:sender
{
  	NXBeep();

	if (!moreInfoPanel)
		[NXApp loadNibSection:"moreInfo.nib" owner:self];
		
	[moreInfoPanel makeKeyAndOrderFront:self];
	
    return self;
}


- printPad:sender
{

	[pad printPSCode:self];

	return self;
}


- showFindPanel:sender
{
	[findPanel makeKeyAndOrderFront:self];

	return self;
}


- findNext:sender
{
	targetText = [findText stringValue];
		
	if ([pad findText:targetText 
               ignoreCase:YES 
                backwards:NO 
                     wrap:YES] == YES)
	
	NXBeep();

	return self;
}

- findPrevious:sender
{
	targetText = [findText stringValue];
		
	if ([pad findText:targetText
               ignoreCase:YES
                backwards:YES 
                     wrap:YES] == YES)
		
	NXBeep();
		
	return self;
}



- clipStuff:(id)pasteboard 
{
	NXBeep();
/*
    	[pasteboard types];    // pretend to check the pasteboard types
       
	[pad readSelectionFromPasteboard: pasteboard];
*/
	return self;
}



@end
